package com.adingxiong.cft.config;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @ClassName ApplicationProperties
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/6/18 10:37
 **/
@Data
@ConfigurationProperties(prefix = "application",ignoreInvalidFields = true)
@Slf4j
public class ApplicationProperties implements InitializingBean {

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("读取配置applicat:{}" ,getTokenHead());
        if (StringUtils.isBlank(getSecretKey())) {
            throw new IllegalStateException("Property \"application.secretkey\" cannot  be blank");
        }
        if(StringUtils.isBlank(getCompany())){
            throw new IllegalStateException("Property 'application.company' cannot be blank");
        }
        if(StringUtils.isBlank(getUploadPath())){
            throw new IllegalStateException("Property 'application.upload-path' cannot be blank");
        }
        if(StringUtils.isBlank(getTokenHead())){
            throw new IllegalStateException("Property 'application.tokenHead' cannot be blank");
        }
        if(StringUtils.isBlank(getTokenHeader())){
            throw new IllegalStateException("Property 'application.tokenHeader' cannot be blank");
        }
        if(StringUtils.isBlank(getSecret())){
            throw new IllegalStateException("Property 'application.secret' cannot be blank");
        }

    }

    /**
     *  实现初始化InitializingBean的类  可以在项目还在的时候 进行参数检查  检查读取配置文件是否成功
     */



    //加密密钥
    private String secretKey;


    private String company;

    private String uploadPath;

    private String tokenHeader;

    private String secret;

    private long expiration;

    private String tokenHead;

    private String esHost;

    private Integer esPort;

}
